package com.jy.adscm.operation.base.controller;


import com.jy.adscm.annotation.AdscmLogger;
import com.jy.adscm.bean.system.JyDept;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.base.bean.TaskManager;
import com.jy.adscm.operation.base.bean.TaskManagerAnalysis;
import com.jy.adscm.operation.base.bean.TaskManagerAnalysisPieChart;
import com.jy.adscm.operation.base.bean.TaskManagerAnalysisSelfWorthPieChart;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2018-12-11
 */
@RestController
@RequestMapping("/adscm/operation/taskManagerAnalysis")
public class TaskManagerAnalysisController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    com.jy.adscm.operation.base.service.TaskManagerAnalysisService taskManagerAnalysisService;


    /**
     * 根据完成状态查询每日完成状况
     * @param userId
     * @param startTime
     * @param endTime
     * @param request
     * @return
     * @throws AdscmSystemException
     */
    @AdscmLogger("根据完成状态查询每日完成状况")
    @RequestMapping("queryTaskManagerAnalysis/{userId}/{startTime}/{endTime}")
    public SimpleCoreResponse queryTaskManagerAnalysis(@PathVariable String userId ,@PathVariable String startTime ,
                                                       @PathVariable String endTime ,HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        List<TaskManagerAnalysis> taskManagerAnalyses = taskManagerAnalysisService.queryTaskManagerAnalysis(userId, startTime, endTime);
        return new SimpleCoreResponse("200","查询成功",taskManagerAnalyses);
    }

    /**
     * 任务分成两类，一是每日，一个计划
     * @param userId
     * @param startTime
     * @param endTime
     * @param request
     * @return
     * @throws AdscmSystemException
     */
    @AdscmLogger("查询每日统计")
    @RequestMapping("queryTaskManager/{userId}/{startTime}/{endTime}")
    public SimpleCoreResponse queryTaskManager(@PathVariable String userId ,@PathVariable String startTime ,
                                                       @PathVariable String endTime ,HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        List<TaskManagerAnalysis> taskManagerAnalyses = taskManagerAnalysisService.queryTaskManager(userId, startTime, endTime);
        return new SimpleCoreResponse("200","查询成功",taskManagerAnalyses);
    }
    @AdscmLogger("查询每日饼图统计")
    @RequestMapping("queryPieChartTime/{userId}/{startTime}/{endTime}")
    public SimpleCoreResponse queryPieChartTime(@PathVariable String userId ,@PathVariable String startTime ,
                                                       @PathVariable String endTime ,HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        List<TaskManagerAnalysisPieChart> taskManagerAnalyses = taskManagerAnalysisService.queryPieChartTime(userId, startTime, endTime);
        return new SimpleCoreResponse("200","查询成功",taskManagerAnalyses);
    }
    @AdscmLogger("查询缔造价值自我评价饼图统计")
    @RequestMapping("querySelfWorthPieChart/{userId}/{startTime}/{endTime}")
    public SimpleCoreResponse querySelfWorthPieChart(@PathVariable String userId ,@PathVariable String startTime ,
                                                       @PathVariable String endTime ,HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        List<TaskManagerAnalysisSelfWorthPieChart> taskManagerAnalyses = taskManagerAnalysisService.querySelfWorthPieChart(userId, startTime, endTime);
        return new SimpleCoreResponse("200","查询成功",taskManagerAnalyses);
    }
    @RequestMapping("queryUser")
    public SimpleCoreResponse queryUser() throws AdscmSystemException {
        List<JyUser> jyUsers = taskManagerAnalysisService.queryUser();
        return new SimpleCoreResponse("200","查询成功",jyUsers);
    }


}

